<template>
    <section class="chart-container">
        <el-row>
            <el-col :span="6">
                <div class="summary-div" >
                    <img />
                    <span style="font-size: 28px">注册数</span>
                    <span style="font-size: 20px">23485</span>
                </div>
            </el-col>
            <el-col :span="6">
                <div class="summary-div" >
                    <img />
                    <span style="font-size: 28px">课程数</span>
                    <span style="font-size: 20px">38495</span>
                </div>
            </el-col>
            <el-col :span="6">
                <div class="summary-div" >
                    <img />
                    <span style="font-size: 28px">订单数</span>
                    <span style="font-size: 20px">539733</span>
                </div>
            </el-col>
            <el-col :span="6">
                <div class="summary-div" >
                    <img />
                    <span style="font-size: 28px">讲师数</span>
                    <span style="font-size: 20px">873</span>
                </div>
            </el-col>
        </el-row>
        <br/>

        <el-row>
            <el-col :span="23" style="background-color: #f0f0f0;border-radius: 0px;padding: 10px">
                <div id="chartLine"   style="width:100% !important; height:300px;"></div>
            </el-col>
        </el-row>


        <el-row>
            <el-col :span="8" class="charcol">
                <div id="chartColumn" style="width:90%; height:300px;"></div>
            </el-col>
            <el-col :span="8" class="charcol">
                <div id="chartBar" style="width:90%; height:300px;"></div>
            </el-col>

            <el-col :span="8" class="charcol">
                <div id="chartPie" style="width:90%; height:300px;"></div>
            </el-col>
        </el-row>
        <br/>
    </section>
</template>

<script>
    import echarts from 'echarts'

    export default {
        data() {
            return {
                chartColumn: null,
                chartBar: null,
                chartLine: null,
                chartPie: null
            }
        },

        methods: {
            drawColumnChart() {
                this.chartColumn = echarts.init(document.getElementById('chartColumn'));
                this.chartColumn.setOption({
                  title: { text: '课程报表' },
                  tooltip: {},
                  xAxis: {
                      data: ["2021-07", "2021-08", "2021-09", "2021-10", "2021-11", "2021-12"]
                  },
                  yAxis: {},
                  series: [{
                      name: '销量',
                      type: 'bar',
                      data: [5, 20, 36, 10, 10, 20]
                    }]
                });
            },
            drawBarChart() {
                this.chartBar = echarts.init(document.getElementById('chartBar'));
                this.chartBar.setOption({
                    title: {
                        text: '用户报表',
                        subtext: '数据来自网络'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    legend: {
                        data: ['2011年', '2012年']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                    },
                    yAxis: {
                        type: 'category',
                        data: ['巴西', '印尼', '美国', '印度', '中国', '用户统计(万)']
                    },
                    series: [
                        {
                            name: '2011年',
                            type: 'bar',
                            data: [18203, 23489, 29034, 104970, 131744, 630230]
                        },
                        {
                            name: '2012年',
                            type: 'bar',
                            data: [19325, 23438, 31000, 121594, 134141, 681807]
                        }
                    ]
                });
            },
            drawLineChart() {
                this.chartLine = echarts.init(document.getElementById('chartLine'));
                this.chartLine.setOption({
                    title: {
                        text: '销量走势图'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['邮件营销', '联盟广告', '搜索引擎']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '邮件营销',
                            type: 'line',
                            stack: '总量',
                            data: [120, 132, 101, 134, 90, 230, 210]
                        },
                        {
                            name: '联盟广告',
                            type: 'line',
                            stack: '总量',
                            data: [220, 182, 191, 234, 290, 330, 310]
                        },
                        {
                            name: '搜索引擎',
                            type: 'line',
                            stack: '总量',
                            data: [820, 932, 901, 934, 1290, 1330, 1320]
                        }
                    ]
                });
            },
            drawPieChart() {
                this.chartPie = echarts.init(document.getElementById('chartPie'));
                this.chartPie.setOption({
                    title: {
                        text: '访问来源',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: [
                                { value: 335, name: '直接访问' },
                                { value: 310, name: '邮件营销' },
                                { value: 234, name: '联盟广告' },
                                { value: 135, name: '视频广告' },
                                { value: 1548, name: '搜索引擎' }
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
            },
            drawCharts() {
                this.drawColumnChart()
                this.drawBarChart()
                this.drawLineChart()
                this.drawPieChart()
            },
        },

        mounted: function () {
            this.drawCharts()
        },
        updated: function () {
            this.drawCharts()
        }
    }
</script>

<style scoped>
    .chart-container {
        width: 100%;
        float: left;
    }
    /*.chart div {
        height: 400px;
        float: left;
    }*/
    .charcol{
        padding: 5px;
        background: #f0f0f0;
        margin: 6px;
        width: 31%;
        border-radius: 0px;
    }
    .chartLine{
        background: #f0f0f0;
        border-radius: 0px;
    }
    .summary-div{
        width:85%; height:100px;background-color: #f1f1f1;border-radius: 0px;line-height: 100px;text-align: center
    }
</style>
